package com.wnxy.mallserver.controller;

import com.wnxy.mallserver.response.ResponseResult;
import com.wnxy.mallserver.service.OrderService;
import com.wnxy.mallserver.vo.order.AddOrderVo;
import com.wnxy.mallserver.vo.order.OrderInfoVo;
import com.wnxy.mallserver.vo.order.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    //添加一条订单信息，返回一条订单信息
//    @RequirePerms("order:add")
    @PostMapping("/addOrder")
    public ResponseResult<OrderVo> addOrder(@RequestBody AddOrderVo addOrderVo, HttpSession session){
        //获取用户id
        int uid = (int) session.getAttribute("uid" );
        //将uid放进订单实体类
        addOrderVo.setUid(uid);
        //返回订单信息
        return  new ResponseResult<>(ResponseResult.OK,orderService.addOrder(addOrderVo));
    }

//    @RequirePerms("order:find")
    @GetMapping("/findByOrderno/{no}")
    public ResponseResult<OrderInfoVo> findByOrderno(@PathVariable("no") String orderno){

        return new ResponseResult<>(ResponseResult.OK,orderService.findByOrderno(orderno));

    }
}
